package com.weic.easycache.framework.db;

import java.lang.reflect.ParameterizedType;
import java.sql.SQLException;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;

public abstract class Table<T, ID> {
	public static final String TAG = "Table<T, ID>";
	public static final Table<ApiCacheTable, String> ApiCache = new Table<ApiCacheTable, String>(){};

	public final Class<T> clazz;

	@SuppressWarnings("unchecked")
	public Table() {
		clazz = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
		if(ApiCache != null && clazz.getSimpleName().equalsIgnoreCase(ApiCache.clazz.getSimpleName())) throw new IllegalArgumentException("自定义数据库实体类名称不应为" + ApiCache.clazz.getSimpleName());
	}

	public final Dao<T, ID> getDao(OrmLiteSqliteOpenHelper helper) throws SQLException {
		return helper.getDao(clazz);
	}
}
